{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 电商用户行为分析\n",
    "#### 本文将按以下方式进行分析\n",
    "1. 背景\n",
    "2. 提出问题\n",
    "3. 理解数据\n",
    "4. 清洗数据\n",
    "5. 可视化分析\n",
    "6. 结论与建议\n",
    "\n",
    "##### 背景\n",
    "客户不同时间段对产品的浏览、收藏、加购、购买等行为一定程度上反应了产品对客户的吸引程度，所以对客户在不同时间的不同行为进行分析，可观察不同的促销活动对客户的吸引程度，用以判断活动是否有促进消费的效果，以及有效针对不同客户群制定一系列的活动来提高消费率。\n",
    "##### 提出问题\n",
    "1. 对诸如“双十二”这样的促销活动进行分析，观察活动是否对客户的购买率有帮助。\n",
    "2. 对“双十二”这样的大型促销活动的当天进行分析，观察不同时间段客户的不同行为特征。\n",
    "3. 对比活动期间和日常期间的客户活跃程度，针对性分析得出活动是否有效的结论。\n",
    "4. 对客户行为进行漏斗分析，得出能够有效提高客户购买率的可行策略\n",
    "##### 理解数据\n",
    "user_id:用户标识  \n",
    "item_id:产品标识  \n",
    "behavior_type:用户行为，包括浏览、收藏、加入购物车、购买，分别对应取值1、2、3、4  \n",
    "user_geohash:用户地理位置标识  \n",
    "item_category:产品分类  \n",
    "time:行为事件\n",
    "##### 清洗数据\n",
    "1. 数据完整性：对空值数据进行处理\n",
    "2. 数据独立性：对重复数据进行处理\n",
    "3. 数据格式检查：转换数据为合适处理的数据类型，对不符合常理的数据进行处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 导入库\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.globals import ThemeType\n",
    "from pyecharts.charts import Bar,Line,Funnel,Grid,Page\n",
    "\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "\n",
    "large = 22\n",
    "med = 16\n",
    "small = 12\n",
    "params = {\n",
    "    'font.sans-serif':['SimHei'],\n",
    "    'figure.figsize':(16,12),\n",
    "    'figure.titlesize':large,\n",
    "    'axes.unicode_minus':False,\n",
    "    'axes.titlesize':med,\n",
    "    'xtick.labelsize':med,\n",
    "    'ytick.labelsize':med,\n",
    "    'legend.fontsize':med\n",
    "}\n",
    "plt.rcParams.update(params)\n",
    "sns.set_color_codes()\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 23291027 entries, 0 to 23291026\n",
      "Data columns (total 6 columns):\n",
      " #   Column         Dtype \n",
      "---  ------         ----- \n",
      " 0   user_id        int64 \n",
      " 1   item_id        int64 \n",
      " 2   behavior_type  int64 \n",
      " 3   user_geohash   object\n",
      " 4   item_category  int64 \n",
      " 5   time           object\n",
      "dtypes: int64(4), object(2)\n",
      "memory usage: 1.0+ GB\n",
      "None\n",
      "            user_id       item_id  behavior_type  item_category\n",
      "count  2.329103e+07  2.329103e+07   2.329103e+07   2.329103e+07\n",
      "mean   7.006868e+07  2.023214e+08   1.106268e+00   6.835397e+03\n",
      "std    4.569072e+07  1.167440e+08   4.599087e-01   3.812873e+03\n",
      "min    4.920000e+02  3.700000e+01   1.000000e+00   2.000000e+00\n",
      "25%    3.019541e+07  1.014417e+08   1.000000e+00   3.690000e+03\n",
      "50%    5.626942e+07  2.022430e+08   1.000000e+00   6.054000e+03\n",
      "75%    1.166482e+08  3.035325e+08   1.000000e+00   1.027100e+04\n",
      "max    1.424430e+08  4.045625e+08   4.000000e+00   1.408000e+04\n",
      "    user_id    item_id  behavior_type user_geohash  item_category  \\\n",
      "0  10001082  285259775              1      97lk14c           4076   \n",
      "1  10001082    4368907              1          NaN           5503   \n",
      "2  10001082    4368907              1          NaN           5503   \n",
      "3  10001082   53616768              1          NaN           9762   \n",
      "4  10001082  151466952              1          NaN           5232   \n",
      "\n",
      "            time  \n",
      "0  2014-12-08 18  \n",
      "1  2014-12-12 12  \n",
      "2  2014-12-12 12  \n",
      "3  2014-12-02 15  \n",
      "4  2014-12-12 11  \n"
     ]
    }
   ],
   "source": [
    "# 读取数据\n",
    "import os\n",
    "path = os.getcwd() + r'/原始数据'\n",
    "user = pd.read_csv(path + r'/tianchi_fresh_comp_train_user.csv')\n",
    "print(user.info())\n",
    "print(user.describe())\n",
    "print(user.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id                 0\n",
       "item_id                 0\n",
       "behavior_type           0\n",
       "user_geohash     15911010\n",
       "item_category           0\n",
       "time                    0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 统计缺失值\n",
    "user.isnull().sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "由于无需对地区进行分析，所以缺失值不处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除重复值\n",
    "user.drop_duplicates(keep='last',inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据格式转换\n",
    "user['time'] = pd.to_datetime(user['time'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 提取日期和时间\n",
    "user['dates'] = user.time.dt.date\n",
    "user['month'] = user.dates.values.astype('datetime64[M]')\n",
    "user['hours'] = user.time.dt.hour"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 转换数据类型\n",
    "user['behavior_type'] = user['behavior_type'].apply(str)\n",
    "user['user_id'] = user['user_id'].apply(str)\n",
    "user['item_id'] = user['item_id'].apply(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 可视化分析\n",
    "# 每日pv\n",
    "pv_day = user[user['behavior_type']=='1'].groupby('dates')['behavior_type'].count()\n",
    "# 每日uv\n",
    "uv_day = user[user['behavior_type']=='1'].drop_duplicates(['user_id','dates']).groupby('dates')['user_id'].count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 改变单位用于显示\n",
    "pv_day = pv_day.div(10000)\n",
    "uv_day = uv_day.div(10000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"6d9db14c1a9943518df840b25eda922e\" style=\"width:1000px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_6d9db14c1a9943518df840b25eda922e = echarts.init(\n",
       "                    document.getElementById('6d9db14c1a9943518df840b25eda922e'), 'dark', {renderer: 'canvas'});\n",
       "                var option_6d9db14c1a9943518df840b25eda922e = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"pv\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18\",\n",
       "                    39.5982\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19\",\n",
       "                    40.5103\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20\",\n",
       "                    39.2599\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21\",\n",
       "                    37.257\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22\",\n",
       "                    39.0638\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23\",\n",
       "                    42.8205\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24\",\n",
       "                    42.0721\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25\",\n",
       "                    40.3631\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26\",\n",
       "                    39.7048\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27\",\n",
       "                    40.4786\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28\",\n",
       "                    38.3756\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29\",\n",
       "                    39.8341\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30\",\n",
       "                    43.8904\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01\",\n",
       "                    43.5448\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02\",\n",
       "                    44.0729\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03\",\n",
       "                    45.7803\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04\",\n",
       "                    43.1818\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05\",\n",
       "                    40.0873\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06\",\n",
       "                    45.5632\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07\",\n",
       "                    47.8213\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08\",\n",
       "                    48.1243\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09\",\n",
       "                    49.4873\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10\",\n",
       "                    51.0422\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11\",\n",
       "                    61.2238\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12\",\n",
       "                    83.3019\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13\",\n",
       "                    49.4372\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14\",\n",
       "                    50.045\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15\",\n",
       "                    48.9105\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16\",\n",
       "                    47.6857\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17\",\n",
       "                    46.87\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18\",\n",
       "                    45.9362\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\",\n",
       "                        \"symbolSize\": 30\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5c0f\\u503c\",\n",
       "                        \"type\": \"min\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"silent\": false,\n",
       "                \"precision\": 2,\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"top\",\n",
       "                    \"margin\": 8,\n",
       "                    \"align\": \"right\",\n",
       "                    \"formatter\": \"\\u5747\\u503c :{c}\\u4e07\\u6b21\"\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u5e73\\u5747\\u503c\",\n",
       "                        \"type\": \"average\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"uv\",\n",
       "            \"connectNulls\": false,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18\",\n",
       "                    1.253\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19\",\n",
       "                    1.2591\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20\",\n",
       "                    1.252\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21\",\n",
       "                    1.2292\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22\",\n",
       "                    1.217\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23\",\n",
       "                    1.2602\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24\",\n",
       "                    1.2742\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25\",\n",
       "                    1.2564\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26\",\n",
       "                    1.2426\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27\",\n",
       "                    1.2365\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28\",\n",
       "                    1.2157\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29\",\n",
       "                    1.2161\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30\",\n",
       "                    1.2503\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01\",\n",
       "                    1.2803\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02\",\n",
       "                    1.2796\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03\",\n",
       "                    1.2953\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04\",\n",
       "                    1.2842\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05\",\n",
       "                    1.2605\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06\",\n",
       "                    1.2642\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07\",\n",
       "                    1.2933\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08\",\n",
       "                    1.2963\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09\",\n",
       "                    1.2953\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10\",\n",
       "                    1.307\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11\",\n",
       "                    1.3764\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12\",\n",
       "                    1.5306\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13\",\n",
       "                    1.3318\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14\",\n",
       "                    1.3188\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15\",\n",
       "                    1.3426\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16\",\n",
       "                    1.326\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17\",\n",
       "                    1.3042\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18\",\n",
       "                    1.2965\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\",\n",
       "                        \"symbolSize\": 30\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5c0f\\u503c\",\n",
       "                        \"type\": \"min\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"silent\": false,\n",
       "                \"precision\": 2,\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"top\",\n",
       "                    \"margin\": 8,\n",
       "                    \"formatter\": \"\\u5747\\u503c :{c}\\u4e07\\u4eba\"\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u5e73\\u5747\\u503c\",\n",
       "                        \"type\": \"average\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"pv\",\n",
       "                \"uv\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"pv\": true,\n",
       "                \"uv\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"axis\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"cross\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"type\": \"category\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisPointer\": {\n",
       "                \"show\": true,\n",
       "                \"type\": \"shadow\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"2014-11-18\",\n",
       "                \"2014-11-19\",\n",
       "                \"2014-11-20\",\n",
       "                \"2014-11-21\",\n",
       "                \"2014-11-22\",\n",
       "                \"2014-11-23\",\n",
       "                \"2014-11-24\",\n",
       "                \"2014-11-25\",\n",
       "                \"2014-11-26\",\n",
       "                \"2014-11-27\",\n",
       "                \"2014-11-28\",\n",
       "                \"2014-11-29\",\n",
       "                \"2014-11-30\",\n",
       "                \"2014-12-01\",\n",
       "                \"2014-12-02\",\n",
       "                \"2014-12-03\",\n",
       "                \"2014-12-04\",\n",
       "                \"2014-12-05\",\n",
       "                \"2014-12-06\",\n",
       "                \"2014-12-07\",\n",
       "                \"2014-12-08\",\n",
       "                \"2014-12-09\",\n",
       "                \"2014-12-10\",\n",
       "                \"2014-12-11\",\n",
       "                \"2014-12-12\",\n",
       "                \"2014-12-13\",\n",
       "                \"2014-12-14\",\n",
       "                \"2014-12-15\",\n",
       "                \"2014-12-16\",\n",
       "                \"2014-12-17\",\n",
       "                \"2014-12-18\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"name\": \"pv\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"interval\": 20,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{value} \\u4e07\\u6b21\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"min\": 0,\n",
       "            \"max\": 100,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"name\": \"uv\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"interval\": 0.4,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{value} \\u4e07\\u4eba\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"position\": \"right\",\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"min\": 0,\n",
       "            \"max\": 1.6,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"pv\\u4e0euv\\u8d8b\\u52bf\\u56fe\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"dataZoom\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"inside\",\n",
       "        \"realtime\": true,\n",
       "        \"start\": 20,\n",
       "        \"end\": 80,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"zoomLock\": false,\n",
       "        \"filterMode\": \"filter\"\n",
       "    }\n",
       "};\n",
       "                chart_6d9db14c1a9943518df840b25eda922e.setOption(option_6d9db14c1a9943518df840b25eda922e);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x144150da0>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 分析每日pv和uv趋势\n",
    "attr = list(pv_day.index)\n",
    "pvuv = (\n",
    "        Line(init_opts=opts.InitOpts(width='1000px',height='500px',theme=ThemeType.DARK))\n",
    "        .add_xaxis(xaxis_data=attr)\n",
    "        .add_yaxis(\n",
    "            series_name='pv',\n",
    "            y_axis=pv_day.values.tolist(),\n",
    "            label_opts=opts.LabelOpts(is_show=False),\n",
    "            markpoint_opts=opts.MarkPointOpts(\n",
    "                data=[\n",
    "                    opts.MarkPointItem(name='最大值',type_='max',symbol_size=30),\n",
    "                    opts.MarkPointItem(name='最小值',type_='min')\n",
    "                ]\n",
    "            ),\n",
    "            markline_opts=opts.MarkLineOpts(\n",
    "                data=[opts.MarkLineItem(name='平均值',type_='average')],\n",
    "                label_opts=opts.LabelOpts(formatter='均值 :{c}万次',horizontal_align='right')\n",
    "            ),\n",
    "        )\n",
    "        .add_yaxis(\n",
    "            series_name='uv',\n",
    "            yaxis_index=1,\n",
    "            y_axis=uv_day.values.tolist(),\n",
    "            label_opts=opts.LabelOpts(is_show=False),\n",
    "            markpoint_opts=opts.MarkPointOpts(\n",
    "                data=[\n",
    "                    opts.MarkPointItem(name='最大值',type_='max',symbol_size=30),\n",
    "                    opts.MarkPointItem(name='最小值',type_='min')\n",
    "                ]\n",
    "            ),\n",
    "            markline_opts=opts.MarkLineOpts(\n",
    "                data=[opts.MarkLineItem(name='平均值',type_='average')],\n",
    "                label_opts=opts.LabelOpts(formatter='均值 :{c}万人')\n",
    "            ),\n",
    "        )\n",
    "        .extend_axis(\n",
    "            yaxis=opts.AxisOpts(\n",
    "                name='uv',\n",
    "                type_='value',\n",
    "                min_=0,\n",
    "                max_=1.6,\n",
    "                interval=0.4,\n",
    "                position='right',\n",
    "                axislabel_opts=opts.LabelOpts(formatter='{value} 万人')\n",
    "            )\n",
    "        )\n",
    "        .set_global_opts(\n",
    "            tooltip_opts=opts.TooltipOpts(\n",
    "                is_show=True,trigger='axis',axis_pointer_type='cross'\n",
    "            ),\n",
    "            xaxis_opts=opts.AxisOpts(\n",
    "                type_='category',\n",
    "                axispointer_opts=opts.AxisPointerOpts(is_show=True,type_='shadow')\n",
    "            ),\n",
    "            yaxis_opts=opts.AxisOpts(\n",
    "                name='pv',\n",
    "                type_='value',\n",
    "                min_=0,\n",
    "                max_=100,\n",
    "                interval=20,\n",
    "                axislabel_opts=opts.LabelOpts(formatter='{value} 万次'),\n",
    "                splitline_opts=opts.SplitLineOpts(is_show=True),\n",
    "            ),\n",
    "            title_opts=opts.TitleOpts(title='pv与uv趋势图'),\n",
    "            datazoom_opts=opts.DataZoomOpts(type_='inside'),\n",
    "        )\n",
    ")\n",
    "pvuv.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"538ec9eedb61485d9d76298a0bb57179\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_538ec9eedb61485d9d76298a0bb57179 = echarts.init(\n",
       "                    document.getElementById('538ec9eedb61485d9d76298a0bb57179'), 'dark', {renderer: 'canvas'});\n",
       "                var option_538ec9eedb61485d9d76298a0bb57179 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u65b0\\u589epv\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18\",\n",
       "                    null\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19\",\n",
       "                    9121.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20\",\n",
       "                    -12504.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21\",\n",
       "                    -20029.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22\",\n",
       "                    18068.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23\",\n",
       "                    37567.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24\",\n",
       "                    -7484.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25\",\n",
       "                    -17090.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26\",\n",
       "                    -6583.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27\",\n",
       "                    7738.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28\",\n",
       "                    -21030.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29\",\n",
       "                    14585.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30\",\n",
       "                    40563.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01\",\n",
       "                    -3456.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02\",\n",
       "                    5281.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03\",\n",
       "                    17074.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04\",\n",
       "                    -25985.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05\",\n",
       "                    -30945.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06\",\n",
       "                    54759.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07\",\n",
       "                    22581.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08\",\n",
       "                    3030.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09\",\n",
       "                    13630.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10\",\n",
       "                    15549.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11\",\n",
       "                    101816.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12\",\n",
       "                    220781.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13\",\n",
       "                    -338647.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14\",\n",
       "                    6078.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15\",\n",
       "                    -11345.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16\",\n",
       "                    -12248.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17\",\n",
       "                    -8157.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18\",\n",
       "                    -9338.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u65b0\\u589euv\",\n",
       "            \"connectNulls\": false,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18\",\n",
       "                    null\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19\",\n",
       "                    61.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20\",\n",
       "                    -71.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21\",\n",
       "                    -228.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22\",\n",
       "                    -122.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23\",\n",
       "                    432.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24\",\n",
       "                    140.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25\",\n",
       "                    -178.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26\",\n",
       "                    -138.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27\",\n",
       "                    -61.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28\",\n",
       "                    -208.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29\",\n",
       "                    4.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30\",\n",
       "                    342.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01\",\n",
       "                    300.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02\",\n",
       "                    -7.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03\",\n",
       "                    157.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04\",\n",
       "                    -111.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05\",\n",
       "                    -237.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06\",\n",
       "                    37.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07\",\n",
       "                    291.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08\",\n",
       "                    30.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09\",\n",
       "                    -10.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10\",\n",
       "                    117.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11\",\n",
       "                    694.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12\",\n",
       "                    1542.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13\",\n",
       "                    -1988.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14\",\n",
       "                    -130.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15\",\n",
       "                    238.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16\",\n",
       "                    -166.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17\",\n",
       "                    -218.0\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18\",\n",
       "                    -77.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u65b0\\u589epv\",\n",
       "                \"\\u65b0\\u589euv\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u65b0\\u589epv\": true,\n",
       "                \"\\u65b0\\u589euv\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"axis\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"cross\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"type\": \"category\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisPointer\": {\n",
       "                \"show\": true,\n",
       "                \"type\": \"shadow\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": null\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"name\": \"\\u65b0\\u589euv\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"position\": \"right\",\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"pv,uv\\u5dee\\u5f02\\u6027\\u5206\\u6790\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_538ec9eedb61485d9d76298a0bb57179.setOption(option_538ec9eedb61485d9d76298a0bb57179);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x101483a20>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 每日pv、uv差异性分析\n",
    "pv_uv = pd.concat([pv_day,uv_day],join='outer',axis=1)\n",
    "pv_uv.columns = ['pv_day','uv_day']\n",
    "new_day = pv_uv.diff()\n",
    "new_day.columns = ['new_pv','new_uv']\n",
    "\n",
    "attr = new_day.index\n",
    "w = new_day.new_pv.mul(10000).round(decimals=2)\n",
    "v = new_day.new_uv.mul(10000).round(decimals=2)\n",
    "line = (\n",
    "    Line(init_opts=opts.InitOpts(theme=ThemeType.DARK))\n",
    "    .add_xaxis(xaxis_data=attr)\n",
    "    .add_yaxis(\n",
    "        series_name='新增pv',\n",
    "        y_axis=w,\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        series_name='新增uv',\n",
    "        y_axis=v,\n",
    "        yaxis_index=1,\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .extend_axis(\n",
    "        yaxis=opts.AxisOpts(\n",
    "            name='新增uv',\n",
    "            type_='value',\n",
    "            position='right',\n",
    "        )\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        xaxis_opts=opts.AxisOpts(\n",
    "            type_='category',\n",
    "            axispointer_opts=opts.AxisPointerOpts(is_show=True,type_='shadow'),\n",
    "        ),\n",
    "        yaxis_opts=opts.AxisOpts(\n",
    "            type_='value',\n",
    "            splitline_opts=opts.SplitLineOpts(is_show=True)\n",
    "        ),\n",
    "        tooltip_opts=opts.TooltipOpts(\n",
    "            is_show=True,\n",
    "            trigger='axis',\n",
    "            axis_pointer_type='cross',\n",
    "        ),\n",
    "        title_opts=opts.TitleOpts(title='pv,uv差异性分析'),\n",
    "        #datazoom_opts=opts.DataZoomOpts(is_show=True,type_='inside')\n",
    "    )\n",
    ")\n",
    "line.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 不同时期用户行为分析\n",
    "# 收藏、加入购物车、购买人数统计\n",
    "collect = user[user.behavior_type=='2'].groupby('dates')['behavior_type'].count()\n",
    "shopping_cart = user[user.behavior_type=='3'].groupby('dates')['behavior_type'].count()\n",
    "buy = user[user.behavior_type=='4'].groupby('dates')['behavior_type'].count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"8c35cd7d14bb44609c5a8488d8632fe5\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_8c35cd7d14bb44609c5a8488d8632fe5 = echarts.init(\n",
       "                    document.getElementById('8c35cd7d14bb44609c5a8488d8632fe5'), 'dark', {renderer: 'canvas'});\n",
       "                var option_8c35cd7d14bb44609c5a8488d8632fe5 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u6536\\u85cf\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18T00:00:00\",\n",
       "                    13205\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19T00:00:00\",\n",
       "                    13432\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20T00:00:00\",\n",
       "                    13111\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21T00:00:00\",\n",
       "                    12606\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22T00:00:00\",\n",
       "                    12975\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23T00:00:00\",\n",
       "                    14529\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24T00:00:00\",\n",
       "                    13874\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25T00:00:00\",\n",
       "                    13275\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26T00:00:00\",\n",
       "                    13530\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27T00:00:00\",\n",
       "                    13850\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28T00:00:00\",\n",
       "                    13328\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29T00:00:00\",\n",
       "                    13545\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30T00:00:00\",\n",
       "                    14715\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01T00:00:00\",\n",
       "                    14335\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02T00:00:00\",\n",
       "                    15312\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03T00:00:00\",\n",
       "                    16378\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04T00:00:00\",\n",
       "                    15586\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05T00:00:00\",\n",
       "                    14517\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06T00:00:00\",\n",
       "                    15148\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07T00:00:00\",\n",
       "                    16247\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08T00:00:00\",\n",
       "                    15771\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09T00:00:00\",\n",
       "                    15773\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10T00:00:00\",\n",
       "                    15185\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11T00:00:00\",\n",
       "                    16817\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12T00:00:00\",\n",
       "                    19811\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13T00:00:00\",\n",
       "                    14585\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14T00:00:00\",\n",
       "                    15782\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15T00:00:00\",\n",
       "                    15171\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16T00:00:00\",\n",
       "                    14498\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17T00:00:00\",\n",
       "                    14783\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18T00:00:00\",\n",
       "                    13805\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u52a0\\u8d2d\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18T00:00:00\",\n",
       "                    18703\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19T00:00:00\",\n",
       "                    18137\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20T00:00:00\",\n",
       "                    17883\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21T00:00:00\",\n",
       "                    17310\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22T00:00:00\",\n",
       "                    17323\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23T00:00:00\",\n",
       "                    18842\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24T00:00:00\",\n",
       "                    18676\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25T00:00:00\",\n",
       "                    19162\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26T00:00:00\",\n",
       "                    17282\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27T00:00:00\",\n",
       "                    17311\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28T00:00:00\",\n",
       "                    16471\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29T00:00:00\",\n",
       "                    17494\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30T00:00:00\",\n",
       "                    20126\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01T00:00:00\",\n",
       "                    20584\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02T00:00:00\",\n",
       "                    21770\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03T00:00:00\",\n",
       "                    22197\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04T00:00:00\",\n",
       "                    20298\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05T00:00:00\",\n",
       "                    19931\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06T00:00:00\",\n",
       "                    20193\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07T00:00:00\",\n",
       "                    20885\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08T00:00:00\",\n",
       "                    21459\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09T00:00:00\",\n",
       "                    22083\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10T00:00:00\",\n",
       "                    23254\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11T00:00:00\",\n",
       "                    30137\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12T00:00:00\",\n",
       "                    46593\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13T00:00:00\",\n",
       "                    19724\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14T00:00:00\",\n",
       "                    20131\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15T00:00:00\",\n",
       "                    19315\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16T00:00:00\",\n",
       "                    19684\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17T00:00:00\",\n",
       "                    19082\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18T00:00:00\",\n",
       "                    18095\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u8d2d\\u4e70\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"2014-11-18T00:00:00\",\n",
       "                    6115\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-19T00:00:00\",\n",
       "                    5859\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-20T00:00:00\",\n",
       "                    5787\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-21T00:00:00\",\n",
       "                    5701\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-22T00:00:00\",\n",
       "                    5762\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-23T00:00:00\",\n",
       "                    6011\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-24T00:00:00\",\n",
       "                    6337\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-25T00:00:00\",\n",
       "                    6304\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-26T00:00:00\",\n",
       "                    5968\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-27T00:00:00\",\n",
       "                    6234\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-28T00:00:00\",\n",
       "                    5563\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-29T00:00:00\",\n",
       "                    5764\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-11-30T00:00:00\",\n",
       "                    6382\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-01T00:00:00\",\n",
       "                    6500\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-02T00:00:00\",\n",
       "                    6642\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-03T00:00:00\",\n",
       "                    6919\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-04T00:00:00\",\n",
       "                    6531\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-05T00:00:00\",\n",
       "                    5587\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-06T00:00:00\",\n",
       "                    6034\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-07T00:00:00\",\n",
       "                    6049\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-08T00:00:00\",\n",
       "                    6172\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-09T00:00:00\",\n",
       "                    5927\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-10T00:00:00\",\n",
       "                    6166\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-11T00:00:00\",\n",
       "                    6273\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-12T00:00:00\",\n",
       "                    28234\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-13T00:00:00\",\n",
       "                    6428\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-14T00:00:00\",\n",
       "                    6306\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-15T00:00:00\",\n",
       "                    6786\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-16T00:00:00\",\n",
       "                    6800\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-17T00:00:00\",\n",
       "                    6530\n",
       "                ],\n",
       "                [\n",
       "                    \"2014-12-18T00:00:00\",\n",
       "                    6384\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u6536\\u85cf\\u4eba\\u6570\",\n",
       "                \"\\u52a0\\u8d2d\\u4eba\\u6570\",\n",
       "                \"\\u8d2d\\u4e70\\u4eba\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u6536\\u85cf\\u4eba\\u6570\": true,\n",
       "                \"\\u52a0\\u8d2d\\u4eba\\u6570\": true,\n",
       "                \"\\u8d2d\\u4e70\\u4eba\\u6570\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"axis\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"cross\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"type\": \"time\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisPointer\": {\n",
       "                \"show\": true,\n",
       "                \"type\": \"shadow\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"2014-11-18T00:00:00\",\n",
       "                \"2014-11-19T00:00:00\",\n",
       "                \"2014-11-20T00:00:00\",\n",
       "                \"2014-11-21T00:00:00\",\n",
       "                \"2014-11-22T00:00:00\",\n",
       "                \"2014-11-23T00:00:00\",\n",
       "                \"2014-11-24T00:00:00\",\n",
       "                \"2014-11-25T00:00:00\",\n",
       "                \"2014-11-26T00:00:00\",\n",
       "                \"2014-11-27T00:00:00\",\n",
       "                \"2014-11-28T00:00:00\",\n",
       "                \"2014-11-29T00:00:00\",\n",
       "                \"2014-11-30T00:00:00\",\n",
       "                \"2014-12-01T00:00:00\",\n",
       "                \"2014-12-02T00:00:00\",\n",
       "                \"2014-12-03T00:00:00\",\n",
       "                \"2014-12-04T00:00:00\",\n",
       "                \"2014-12-05T00:00:00\",\n",
       "                \"2014-12-06T00:00:00\",\n",
       "                \"2014-12-07T00:00:00\",\n",
       "                \"2014-12-08T00:00:00\",\n",
       "                \"2014-12-09T00:00:00\",\n",
       "                \"2014-12-10T00:00:00\",\n",
       "                \"2014-12-11T00:00:00\",\n",
       "                \"2014-12-12T00:00:00\",\n",
       "                \"2014-12-13T00:00:00\",\n",
       "                \"2014-12-14T00:00:00\",\n",
       "                \"2014-12-15T00:00:00\",\n",
       "                \"2014-12-16T00:00:00\",\n",
       "                \"2014-12-17T00:00:00\",\n",
       "                \"2014-12-18T00:00:00\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u4e0d\\u540c\\u65f6\\u671f\\u7528\\u6237\\u884c\\u4e3a\\u5206\\u6790\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_8c35cd7d14bb44609c5a8488d8632fe5.setOption(option_8c35cd7d14bb44609c5a8488d8632fe5);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x51476ac8>"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "attr = list(collect.index)\n",
    "b = (\n",
    "    Line(init_opts=opts.InitOpts(theme=ThemeType.DARK))\n",
    "    .add_xaxis(xaxis_data=attr)\n",
    "    .add_yaxis(\n",
    "        series_name='收藏人数',\n",
    "        y_axis=collect.values.tolist(),\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        series_name='加购人数',\n",
    "        y_axis=shopping_cart.values.tolist(),\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        series_name='购买人数',\n",
    "        y_axis=buy.values.tolist(),\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='不同时期用户行为分析'),\n",
    "        tooltip_opts=opts.TooltipOpts(\n",
    "            is_show=True,\n",
    "            trigger='axis',\n",
    "            axis_pointer_type='cross',\n",
    "        ),\n",
    "        xaxis_opts=opts.AxisOpts(\n",
    "            type_='time',\n",
    "            axispointer_opts=opts.AxisPointerOpts(is_show=True,type_='shadow'),\n",
    "        ),\n",
    "        yaxis_opts=opts.AxisOpts(\n",
    "            type_='value',\n",
    "            splitline_opts=opts.SplitLineOpts(is_show=True)\n",
    "        )\n",
    "    )\n",
    ")\n",
    "b.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 拆分数据为活动数据和日常数据作不同时段分析\n",
    "user['dates'] = pd.to_datetime(user['dates'])\n",
    "active = user[user['dates'].isin([\"2014/12/11\",\"2014/12/12\",\"2014/12/13\"])]\n",
    "daily = user[~user['dates'].isin([\"2014/12/11\",\"2014/12/12\",\"2014/12/13\"])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 活动数据分析\n",
    "# 浏览次数\n",
    "pv_h = active[active.behavior_type=='1'].groupby('hours')['user_id'].count()\n",
    "# 收藏人数\n",
    "collect_h = active[active.behavior_type=='2'].groupby('hours')['behavior_type'].count()\n",
    "# 加购人数\n",
    "cart_h = active[active.behavior_type=='3'].groupby('hours')['behavior_type'].count()\n",
    "# 购买人数\n",
    "buy_h = active[active.behavior_type=='4'].groupby('hours')['behavior_type'].count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"0ab1fb3681f34d9b85744ee30028caeb\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_0ab1fb3681f34d9b85744ee30028caeb = echarts.init(\n",
       "                    document.getElementById('0ab1fb3681f34d9b85744ee30028caeb'), 'dark', {renderer: 'canvas'});\n",
       "                var option_0ab1fb3681f34d9b85744ee30028caeb = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u6d4f\\u89c8\\u4eba\\u6570\",\n",
       "            \"xAxisIndex\": 0,\n",
       "            \"yAxisIndex\": 0,\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                24245.0,\n",
       "                11339.0,\n",
       "                6523.0,\n",
       "                4108.0,\n",
       "                3127.0,\n",
       "                3423.0,\n",
       "                6896.0,\n",
       "                17542.0,\n",
       "                23936.0,\n",
       "                26497.0,\n",
       "                30613.0,\n",
       "                27772.0,\n",
       "                28740.0,\n",
       "                30943.0,\n",
       "                29105.0,\n",
       "                30017.0,\n",
       "                28863.0,\n",
       "                25350.0,\n",
       "                28554.0,\n",
       "                39194.0,\n",
       "                48822.0,\n",
       "                60389.0,\n",
       "                60660.0,\n",
       "                49884.0\n",
       "            ],\n",
       "            \"showBackground\": false,\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u6536\\u85cf\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    845.0\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    395.0\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    290.0\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    136.0\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    107.0\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    101.0\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    228.0\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    405.0\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    653.0\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    635.0\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    809.0\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    691.0\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    764.0\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    844.0\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    798.0\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    769.0\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    760.0\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    745.0\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    742.0\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    904.0\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    1205.0\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    1379.0\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    1583.0\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    1284.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u52a0\\u8d2d\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    2100.0\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    744.0\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    406.0\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    257.0\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    235.0\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    286.0\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    431.0\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    700.0\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    1058.0\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    1249.0\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    1509.0\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    1416.0\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    1323.0\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    1481.0\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    1394.0\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    1380.0\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    1310.0\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    1223.0\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    1283.0\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    1675.0\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    2131.0\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    2675.0\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    2878.0\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    3007.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u8d2d\\u4e70\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    1492.0\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    314.0\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    180.0\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    94.0\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    81.0\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    93.0\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    196.0\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    342.0\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    527.0\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    674.0\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    767.0\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    745.0\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    653.0\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    712.0\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    601.0\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    618.0\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    584.0\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    474.0\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    519.0\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    600.0\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    729.0\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    867.0\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    825.0\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    959.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u6d4f\\u89c8\\u4eba\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u6d4f\\u89c8\\u4eba\\u6570\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        },\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u6536\\u85cf\\u4eba\\u6570\",\n",
       "                \"\\u52a0\\u8d2d\\u4eba\\u6570\",\n",
       "                \"\\u8d2d\\u4e70\\u4eba\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u6536\\u85cf\\u4eba\\u6570\": true,\n",
       "                \"\\u52a0\\u8d2d\\u4eba\\u6570\": true,\n",
       "                \"\\u8d2d\\u4e70\\u4eba\\u6570\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"top\": \"48%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                0,\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23\n",
       "            ]\n",
       "        },\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 1,\n",
       "            \"axisTick\": {\n",
       "                \"show\": true,\n",
       "                \"alignWithLabel\": true,\n",
       "                \"inside\": false\n",
       "            },\n",
       "            \"axisPointer\": {\n",
       "                \"show\": true,\n",
       "                \"type\": \"shadow\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"boundaryGap\": true,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                0,\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 1,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6d3b\\u52a8pv\\u5bf9\\u6bd4\\u6570\\u636e\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        },\n",
       "        {\n",
       "            \"text\": \"\\u65e5\\u5747\\u5404\\u65f6\\u6bb5\\u6d3b\\u52a8\\u7528\\u6237\\u884c\\u4e3a\",\n",
       "            \"top\": \"48%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"grid\": [\n",
       "        {\n",
       "            \"show\": false,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"bottom\": \"60%\",\n",
       "            \"containLabel\": false,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1\n",
       "        },\n",
       "        {\n",
       "            \"show\": false,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"top\": \"60%\",\n",
       "            \"containLabel\": false,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1\n",
       "        }\n",
       "    ],\n",
       "    \"color\": []\n",
       "};\n",
       "                chart_0ab1fb3681f34d9b85744ee30028caeb.setOption(option_0ab1fb3681f34d9b85744ee30028caeb);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x51476320>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "attr_h = list(collect_h.index)\n",
    "h1 = np.around(collect_h.values/3,decimals=0).tolist()\n",
    "h2 = np.around(cart_h.values/3,decimals=0).tolist()\n",
    "h3 = np.around(buy_h.values/3,decimals=0).tolist()\n",
    "h4 = np.around(pv_h.values/3,decimals=0).tolist()\n",
    "h = (\n",
    "    Line(init_opts=opts.InitOpts(theme=ThemeType.DARK))\n",
    "    .add_xaxis(xaxis_data=attr_h)\n",
    "    .add_yaxis(\n",
    "        series_name='收藏人数',\n",
    "        y_axis=h1,\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        series_name='加购人数',\n",
    "        y_axis=h2,\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        series_name='购买人数',\n",
    "        y_axis=h3,\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        xaxis_opts=opts.AxisOpts(\n",
    "            boundary_gap=True,\n",
    "            axistick_opts=opts.AxisTickOpts(is_align_with_label=True),\n",
    "            axispointer_opts=opts.AxisPointerOpts(is_show=True,type_='shadow')\n",
    "        ),\n",
    "        yaxis_opts=opts.AxisOpts(type_='value'),\n",
    "        title_opts=opts.TitleOpts('日均各时段活动用户行为',pos_top='48%'),\n",
    "        tooltip_opts=opts.TooltipOpts(is_show=True,trigger='axis',axis_pointer_type='cross'),\n",
    "        legend_opts=opts.LegendOpts(pos_top='48%'),\n",
    "    )\n",
    ")\n",
    "bar = (\n",
    "    Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK))\n",
    "    .add_xaxis(xaxis_data=attr_h)\n",
    "    .add_yaxis(\n",
    "        series_name='浏览人数',\n",
    "        y_axis=h4,\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='活动pv对比数据'),\n",
    "        tooltip_opts=opts.TooltipOpts(trigger='item')\n",
    "    )\n",
    ")\n",
    "ggrid = (\n",
    "    Grid(init_opts=opts.InitOpts(theme=ThemeType.DARK))\n",
    "    .add(bar,grid_opts=opts.GridOpts(pos_bottom='60%'))\n",
    "    .add(h,grid_opts=opts.GridOpts(pos_top='60%'))\n",
    ")\n",
    "ggrid.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "————活动期间的日均数据，可看出活动期间用户的在0点时达到购买高峰，点击浏览的高峰集中的21-22点之间，因此在19点前准备好促销活动所需页面和广告，可吸引客户在0点参加购买活动。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 日常数据分析\n",
    "# 浏览次数\n",
    "pv_d = daily[daily.behavior_type=='1'].groupby('hours')['user_id'].count()\n",
    "# 收藏人数\n",
    "collect_d = daily[daily.behavior_type=='2'].groupby('hours')['behavior_type'].count()\n",
    "# 加购人数\n",
    "cart_d = daily[daily.behavior_type=='3'].groupby('hours')['behavior_type'].count()\n",
    "# 购买人数\n",
    "buy_d = daily[daily.behavior_type=='4'].groupby('hours')['behavior_type'].count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"8d45d117defd4810a1b859a56f0d37ee\" style=\"width:1000px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_8d45d117defd4810a1b859a56f0d37ee = echarts.init(\n",
       "                    document.getElementById('8d45d117defd4810a1b859a56f0d37ee'), 'dark', {renderer: 'canvas'});\n",
       "                var option_8d45d117defd4810a1b859a56f0d37ee = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u6d4f\\u89c8\\u4eba\\u6570\",\n",
       "            \"xAxisIndex\": 0,\n",
       "            \"yAxisIndex\": 0,\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                12765.0,\n",
       "                6614.0,\n",
       "                3819.0,\n",
       "                2516.0,\n",
       "                1997.0,\n",
       "                2229.0,\n",
       "                4423.0,\n",
       "                10037.0,\n",
       "                14059.0,\n",
       "                17009.0,\n",
       "                19921.0,\n",
       "                19160.0,\n",
       "                19980.0,\n",
       "                22204.0,\n",
       "                21846.0,\n",
       "                21946.0,\n",
       "                21561.0,\n",
       "                19209.0,\n",
       "                20903.0,\n",
       "                28234.0,\n",
       "                34893.0,\n",
       "                41243.0,\n",
       "                40216.0,\n",
       "                29425.0\n",
       "            ],\n",
       "            \"showBackground\": false,\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"silent\": false,\n",
       "                \"precision\": 2,\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"top\",\n",
       "                    \"margin\": 8,\n",
       "                    \"formatter\": \"\\u5e73\\u5747\\u503c :{c}\"\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u5e73\\u5747\\u503c\",\n",
       "                        \"type\": \"average\"\n",
       "                    }\n",
       "                ]\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u6536\\u85cf\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    601.0\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    346.0\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    196.0\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    119.0\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    96.0\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    113.0\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    207.0\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    345.0\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    471.0\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    587.0\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    658.0\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    648.0\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    643.0\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    718.0\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    703.0\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    697.0\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    689.0\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    620.0\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    616.0\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    848.0\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    1047.0\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    1193.0\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    1259.0\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    1018.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u52a0\\u8d2d\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    646.0\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    338.0\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    199.0\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    129.0\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    110.0\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    117.0\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    222.0\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    387.0\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    546.0\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    729.0\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    918.0\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    882.0\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    884.0\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    1002.0\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    985.0\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    1032.0\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    988.0\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    821.0\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    869.0\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    1166.0\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    1454.0\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    1790.0\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    1766.0\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    1436.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u8d2d\\u4e70\\u4eba\\u6570\",\n",
       "            \"connectNulls\": false,\n",
       "            \"xAxisIndex\": 1,\n",
       "            \"yAxisIndex\": 1,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    152.0\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    72.0\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    34.0\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    23.0\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    17.0\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    17.0\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    43.0\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    77.0\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    163.0\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    267.0\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    387.0\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    362.0\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    368.0\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    405.0\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    400.0\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    411.0\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    380.0\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    307.0\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    277.0\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    360.0\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    416.0\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    496.0\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    446.0\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    306.0\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u6d4f\\u89c8\\u4eba\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u6d4f\\u89c8\\u4eba\\u6570\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        },\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u6536\\u85cf\\u4eba\\u6570\",\n",
       "                \"\\u52a0\\u8d2d\\u4eba\\u6570\",\n",
       "                \"\\u8d2d\\u4e70\\u4eba\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u6536\\u85cf\\u4eba\\u6570\": true,\n",
       "                \"\\u52a0\\u8d2d\\u4eba\\u6570\": true,\n",
       "                \"\\u8d2d\\u4e70\\u4eba\\u6570\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"top\": \"50%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                0,\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23\n",
       "            ]\n",
       "        },\n",
       "        {\n",
       "            \"name\": \"\\u65f6\\u95f4\\u6bb5\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 1,\n",
       "            \"axisTick\": {\n",
       "                \"show\": true,\n",
       "                \"alignWithLabel\": true,\n",
       "                \"inside\": false\n",
       "            },\n",
       "            \"axisPointer\": {\n",
       "                \"show\": true,\n",
       "                \"type\": \"shadow\"\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"boundaryGap\": true,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                0,\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 1,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u65e5\\u5e38pv\\u5bf9\\u6bd4\\u6570\\u636e\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        },\n",
       "        {\n",
       "            \"text\": \"\\u65e5\\u5747\\u5404\\u65f6\\u6bb5\\u6d3b\\u52a8\\u7528\\u6237\\u884c\\u4e3a\",\n",
       "            \"top\": \"50%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"grid\": [\n",
       "        {\n",
       "            \"show\": false,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"bottom\": \"60%\",\n",
       "            \"containLabel\": false,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1\n",
       "        },\n",
       "        {\n",
       "            \"show\": false,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"top\": \"60%\",\n",
       "            \"containLabel\": false,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1\n",
       "        }\n",
       "    ],\n",
       "    \"color\": []\n",
       "};\n",
       "                chart_8d45d117defd4810a1b859a56f0d37ee.setOption(option_8d45d117defd4810a1b859a56f0d37ee);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x3cf0bc50>"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "attr_d = list(pv_d.index)\n",
    "d_collect = np.around(collect_d.values/28,decimals=0).tolist()\n",
    "d_cart = np.around(cart_d.values/28,decimals=0).tolist()\n",
    "d_buy = np.around(buy_d.values/28,decimals=0).tolist()\n",
    "d_pv = np.around(pv_d.values/28,decimals=0).tolist()\n",
    "l2 = (\n",
    "    Line(init_opts=opts.InitOpts(theme=ThemeType.DARK,width='1000px',height='500px'))\n",
    "    .add_xaxis(xaxis_data=attr_d)\n",
    "    .add_yaxis(\n",
    "        series_name='收藏人数',\n",
    "        y_axis=d_collect,\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        series_name='加购人数',\n",
    "        y_axis=d_cart,\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        series_name='购买人数',\n",
    "        y_axis=d_buy,\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='日均各时段活动用户行为',pos_top='50%'),\n",
    "        legend_opts=opts.LegendOpts(pos_top='50%'),\n",
    "        xaxis_opts=opts.AxisOpts(\n",
    "            name='时间段',\n",
    "            boundary_gap=True,\n",
    "            axistick_opts=opts.AxisTickOpts(is_align_with_label=True),\n",
    "            axispointer_opts=opts.AxisPointerOpts(is_show=True,type_='shadow')\n",
    "        ),\n",
    "        tooltip_opts=opts.TooltipOpts(trigger='axis',axis_pointer_type='shadow'),\n",
    "    )\n",
    ")\n",
    "bar2 = (\n",
    "    Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK,width='1000px',height='500px'))\n",
    "    .add_xaxis(xaxis_data=attr_d)\n",
    "    .add_yaxis(\n",
    "        series_name='浏览人数',\n",
    "        y_axis=d_pv,\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "        markpoint_opts=opts.MarkPointOpts(\n",
    "            data=[opts.MarkPointItem(type_='max',name='最大值')]\n",
    "        ),\n",
    "        markline_opts=opts.MarkLineOpts(\n",
    "            data=[opts.MarkLineItem(type_='average',name='平均值')],\n",
    "            label_opts=opts.LabelOpts(formatter='平均值 :{c}')\n",
    "        ),\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='日常pv对比数据'),\n",
    "        tooltip_opts=opts.TooltipOpts(trigger='item')\n",
    "    )\n",
    ")\n",
    "ggrid2 = (\n",
    "    Grid(init_opts=opts.InitOpts(theme=ThemeType.DARK,width='1000px',height='500px'))\n",
    "    .add(bar2,grid_opts=opts.GridOpts(pos_bottom='60%'))\n",
    "    .add(l2,grid_opts=opts.GridOpts(pos_top='60%'))\n",
    ")\n",
    "ggrid2.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "————日常时期数据与活动时期不同，购买人数不会在0点升高，从上午10点晚上0点变化不会太大。而浏览、收藏、加入购物车人数在晚上19点开始攀升，在晚上21点和晚上22点之间达到高峰，说明用户集中在晚上这个时间段浏览商品，日常时期可集中在这个时间段进行促销活动。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 活动时各时段购买率\n",
    "hour_buy_active_num = active[active.behavior_type=='4'].drop_duplicates(['user_id','dates','hours']).groupby(['hours'])['user_id'].count()\n",
    "hour_active_user_num = active.drop_duplicates(['user_id','dates','hours']).groupby('hours')['user_id'].count()\n",
    "hour_buy_rate_active = hour_buy_active_num / hour_active_user_num\n",
    "# 日常时各时段购买率\n",
    "hour_buy_daily_num = daily[daily.behavior_type=='4'].drop_duplicates(['user_id','dates','hours']).groupby('hours')['user_id'].count()\n",
    "hour_daily_user_num = daily.drop_duplicates(['user_id','dates','hours']).groupby('hours')['user_id'].count()\n",
    "hour_buy_rate_daily = hour_buy_daily_num / hour_daily_user_num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"be2350fdf53f4796b990153649930679\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_be2350fdf53f4796b990153649930679 = echarts.init(\n",
       "                    document.getElementById('be2350fdf53f4796b990153649930679'), 'dark', {renderer: 'canvas'});\n",
       "                var option_be2350fdf53f4796b990153649930679 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u6d3b\\u52a8\\u8d2d\\u4e70\\u7387\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    0.26\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    0.17\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    0.15\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    0.13\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    0.14\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    0.12\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    0.13\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    0.14\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    0.15\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    0.15\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    0.14\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    0.14\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    0.13\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    0.13\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    0.13\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    0.12\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    0.12\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    0.13\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    0.14\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"silent\": false,\n",
       "                \"precision\": 2,\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"top\",\n",
       "                    \"margin\": 8,\n",
       "                    \"formatter\": \"{b} :{c}\"\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u5e73\\u5747\\u503c\",\n",
       "                        \"type\": \"average\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u65e5\\u5e38\\u8d2d\\u4e70\\u7387\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    0,\n",
       "                    0.08\n",
       "                ],\n",
       "                [\n",
       "                    1,\n",
       "                    0.07\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    0.06\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    0.05\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    0.05\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    0.04\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    0.05\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    0.05\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    0.07\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    0.09\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    15,\n",
       "                    0.11\n",
       "                ],\n",
       "                [\n",
       "                    16,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    17,\n",
       "                    0.09\n",
       "                ],\n",
       "                [\n",
       "                    18,\n",
       "                    0.08\n",
       "                ],\n",
       "                [\n",
       "                    19,\n",
       "                    0.09\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    0.09\n",
       "                ],\n",
       "                [\n",
       "                    21,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    22,\n",
       "                    0.09\n",
       "                ],\n",
       "                [\n",
       "                    23,\n",
       "                    0.09\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"silent\": false,\n",
       "                \"precision\": 2,\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"top\",\n",
       "                    \"margin\": 8,\n",
       "                    \"formatter\": \"\\u5e73\\u5747\\u503c: {c}\"\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u5e73\\u5747\\u503c\",\n",
       "                        \"type\": \"average\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u6d3b\\u52a8\\u8d2d\\u4e70\\u7387\",\n",
       "                \"\\u65e5\\u5e38\\u8d2d\\u4e70\\u7387\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u6d3b\\u52a8\\u8d2d\\u4e70\\u7387\": true,\n",
       "                \"\\u65e5\\u5e38\\u8d2d\\u4e70\\u7387\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"name\": \"\\u65f6\\u6bb5\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"center\",\n",
       "            \"nameGap\": \"25\",\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisTick\": {\n",
       "                \"show\": true,\n",
       "                \"alignWithLabel\": true,\n",
       "                \"inside\": false\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"boundaryGap\": true,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                0,\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u4e0d\\u540c\\u65f6\\u6bb5\\u8d2d\\u4e70\\u7387\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_be2350fdf53f4796b990153649930679.setOption(option_be2350fdf53f4796b990153649930679);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x8337e3c8>"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "line3 = (\n",
    "    Line(init_opts=opts.InitOpts(theme=ThemeType.DARK))\n",
    "    .add_xaxis(xaxis_data=list(hour_buy_rate_daily.index))\n",
    "    .add_yaxis(\n",
    "        series_name='活动购买率',\n",
    "        y_axis=np.around(hour_buy_rate_active,decimals=2).tolist(),\n",
    "        markline_opts=opts.MarkLineOpts(\n",
    "            data=[opts.MarkLineItem(name='平均值',type_='average')],\n",
    "            label_opts=opts.LabelOpts(formatter='{b} :{c}'),\n",
    "        )\n",
    "    )\n",
    "    .add_yaxis(\n",
    "        series_name='日常购买率',\n",
    "        y_axis=np.around(hour_buy_rate_daily,decimals=2).tolist(),\n",
    "        markline_opts=opts.MarkLineOpts(\n",
    "            data=[opts.MarkLineItem(name='平均值',type_='average')],\n",
    "            label_opts=opts.LabelOpts(formatter='平均值: {c}'),\n",
    "        )\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='不同时段购买率'),\n",
    "        xaxis_opts=opts.AxisOpts(\n",
    "            name='时段',\n",
    "            name_location='center',\n",
    "            name_gap='25',\n",
    "            boundary_gap=True,\n",
    "            axistick_opts=opts.AxisTickOpts(is_align_with_label=True),\n",
    "        )\n",
    "    )\n",
    ")\n",
    "line3.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "————由上图可明显看出，活动时期的购买率一直高于日常购买率，说明促销活动是有效果的；日常时期的购买率高峰在早上10点、中午14到15点、晚上21点，日常时期可采取措施在这几个时间点提高购买率，而活动购买率从晚上19点开始攀升，到0点达到峰值，说明可在这段时间采取吸引用户购买的措施。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"96c4070603e4496ab3b6233600d21415\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_96c4070603e4496ab3b6233600d21415 = echarts.init(\n",
       "                    document.getElementById('96c4070603e4496ab3b6233600d21415'), 'dark', {renderer: 'canvas'});\n",
       "                var option_96c4070603e4496ab3b6233600d21415 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"funnel\",\n",
       "            \"name\": \"\\u7528\\u6237\\u884c\\u4e3a\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u6d4f\\u89c8\",\n",
       "                    \"value\": 100.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u52a0\\u5165\\u8d2d\\u7269\\u8f66\",\n",
       "                    \"value\": 4.97\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6536\\u85cf\",\n",
       "                    \"value\": 2.64\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d2d\\u4e70\",\n",
       "                    \"value\": 2.11\n",
       "                }\n",
       "            ],\n",
       "            \"sort\": \"descending\",\n",
       "            \"gap\": 1,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"fontSize\": 17,\n",
       "                \"formatter\": \" {b}: {c}%\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u52a0\\u5165\\u8d2d\\u7269\\u8f66\",\n",
       "                \"\\u8d2d\\u4e70\",\n",
       "                \"\\u6d4f\\u89c8\",\n",
       "                \"\\u6536\\u85cf\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u6d4f\\u89c8\": true,\n",
       "                \"\\u52a0\\u5165\\u8d2d\\u7269\\u8f66\": true,\n",
       "                \"\\u6536\\u85cf\": true,\n",
       "                \"\\u8d2d\\u4e70\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u7528\\u6237\\u8f6c\\u5316\\u6f0f\\u6597\",\n",
       "            \"subtext\": \"\\u6d3b\\u52a8\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_96c4070603e4496ab3b6233600d21415.setOption(option_96c4070603e4496ab3b6233600d21415);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x832bfcf8>"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 转化漏斗分析\n",
    "\n",
    "# 活动期间\n",
    "pv_count = active[active.behavior_type=='1']['user_id'].count()\n",
    "cart_count = active[active.behavior_type=='3']['user_id'].count()\n",
    "collect_count = active[active.behavior_type=='2']['user_id'].count()\n",
    "buy_count = active[active.behavior_type=='4']['user_id'].count()\n",
    "\n",
    "attr_funnel = ['浏览','加入购物车','收藏','购买']\n",
    "values = [np.around(pv_count/pv_count*100,2),\n",
    "          np.around(cart_count/pv_count*100,2),\n",
    "          np.around(collect_count/pv_count*100,2),\n",
    "          np.around(buy_count/pv_count*100,2)\n",
    "         ]\n",
    "data = [(x,y) for x,y in zip(attr_funnel,values)]\n",
    "funnel = (\n",
    "    Funnel(init_opts=opts.InitOpts(theme=ThemeType.DARK))\n",
    "    .add(\n",
    "        series_name='用户行为',\n",
    "        data_pair=data,\n",
    "        label_opts=opts.LabelOpts(formatter=' {b}: {c}%',font_size=17,),\n",
    "        gap=1,\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='用户转化漏斗',subtitle='活动')\n",
    "    )\n",
    ")\n",
    "funnel.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "————活动期间从点击浏览到加入购物车的转化率只有4.97%,收藏和购买只有2%左右，说明虽然浏览的人不少，但浏览过后无法吸引其购买，转化率不高，可从考虑提高加入购物车和收藏的比例，从而吸引客户购买。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 日常期间的漏斗转化\n",
    "pv2_count = daily[daily.behavior_type=='1']['user_id'].count()\n",
    "cart2_count = daily[daily.behavior_type=='3']['user_id'].count()\n",
    "collect2_count = daily[daily.behavior_type=='2']['user_id'].count()\n",
    "buy2_count = daily[daily.behavior_type=='4']['user_id'].count()\n",
    "\n",
    "values2 = [np.around(pv2_count/pv2_count*100,2),\n",
    "           np.around(cart2_count/pv2_count*100,2),\n",
    "           np.around(collect2_count/pv2_count*100,2),\n",
    "           np.around(buy2_count/pv2_count*100,2),\n",
    "          ]\n",
    "data2 = [(x,y) for x,y in zip(attr_funnel,values2)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"87877f22c7a64c9687d11964241b0e3b\" style=\"width:1000px; height:600px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_87877f22c7a64c9687d11964241b0e3b = echarts.init(\n",
       "                    document.getElementById('87877f22c7a64c9687d11964241b0e3b'), 'dark', {renderer: 'canvas'});\n",
       "                var option_87877f22c7a64c9687d11964241b0e3b = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"funnel\",\n",
       "            \"name\": \"\\u7528\\u6237\\u884c\\u4e3a\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u6d4f\\u89c8\",\n",
       "                    \"value\": 100.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u52a0\\u5165\\u8d2d\\u7269\\u8f66\",\n",
       "                    \"value\": 4.45\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6536\\u85cf\",\n",
       "                    \"value\": 3.31\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d2d\\u4e70\",\n",
       "                    \"value\": 1.42\n",
       "                }\n",
       "            ],\n",
       "            \"sort\": \"descending\",\n",
       "            \"gap\": 1,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"fontSize\": 17,\n",
       "                \"formatter\": \" {b}:{c}%\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u52a0\\u5165\\u8d2d\\u7269\\u8f66\",\n",
       "                \"\\u8d2d\\u4e70\",\n",
       "                \"\\u6d4f\\u89c8\",\n",
       "                \"\\u6536\\u85cf\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u6d4f\\u89c8\": true,\n",
       "                \"\\u52a0\\u5165\\u8d2d\\u7269\\u8f66\": true,\n",
       "                \"\\u6536\\u85cf\": true,\n",
       "                \"\\u8d2d\\u4e70\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u7528\\u6237\\u8f6c\\u5316\\u6f0f\\u6597\",\n",
       "            \"subtext\": \"\\u65e5\\u5e38\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_87877f22c7a64c9687d11964241b0e3b.setOption(option_87877f22c7a64c9687d11964241b0e3b);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x6740df98>"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "funnel2 = (\n",
    "    Funnel(init_opts=opts.InitOpts(theme=ThemeType.DARK,width='1000px',height='600px'))\n",
    "    .add(\n",
    "        series_name='用户行为',\n",
    "        data_pair=data2,\n",
    "        gap=1,\n",
    "        label_opts=opts.LabelOpts(formatter=' {b}:{c}%',font_size=17)\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='用户转化漏斗',subtitle='日常')\n",
    "    )\n",
    ")\n",
    "funnel2.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "————日常数据中，有4.45%加入购物车、有3.31%收藏、有1.42%购买，总体来看，购买率较低，有很大的提升空间；  \n",
    "————若按照“浏览-加入购物车-收藏-购买”这一用户行为来分析，可通过优化“浏览-加入购物车”这一环节来提升购买率，可以通过发放优惠券或返现活动来鼓励用户加入购物车和收藏行为，从而刺激用户的购买欲望。"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "e94dd2023f21a93510fb04e380baf504272aa09c40641b7e8c2a7346f5fbf161"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  },
  "toc-autonumbering": false,
  "toc-showcode": true,
  "toc-showmarkdowntxt": false,
  "toc-showtags": false
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
